﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Seggu.Helpers
{
    public static class StringExtensions
    {
        public static bool IsAllNumbers(this string str)
        {
            foreach (char c in str)
            {
                if (!char.IsNumber(c))
                {
                    return false;
                }
            }
            return true;
        }

        public static bool IsAllLetters(this string str)
        {
            foreach (char c in str)
            {
                if (!char.IsLetter(c))
                    return false;
            }
            return true;
        }

        public static int ToInt(this string str)
        {
            var i = 0;
            int.TryParse(str, out i);
            return i;
        }

        public static DateTime? ToNullableDateTime(this string str)
        {
            var date = DateTime.MinValue;
            DateTime.TryParse(str, out date);
            return date == DateTime.MinValue ? (DateTime?)null : date;
        }

        public static DateTime ToDateTime(this string str)
        {
            var date = DateTime.MinValue;
            DateTime.TryParse(str, out date);
            return date;
        }

        public static Guid ToGuid(this string str)
        {
            var guid = Guid.Empty;
            Guid.TryParse(str, out guid);
            return guid;
        }
    }
}
